package com.amc.wxSend.service.impl;

import com.amc.common.annotation.CustomCache;
import com.amc.common.annotation.DistributedLock;
import com.amc.wxSend.domain.SysDictData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class RedssionLockServiceImpl {

    @CustomCache(prefix = "sysDict", suffix = "info")
    public SysDictData get(Long id) {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictCode(11111L);
        sysDictData.setDictLabel("性别");
        return null;
    }

    //@DistributedLock(key = "'testRedssion'+#dict.dictCode")
    //@DistributedLock(key = "'testRedssion'+#dict.dictCode",waitTime=4000)
    //@DistributedLock(key = "'testRedssion'+#dict.dictCode",waitTime=4000,leaseTime = 1)
    @DistributedLock(key = "'testRedssion'+#dict.dictCode",waitTime=3,leaseTime = 4)
    public boolean testDistributeLock(SysDictData dict) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("id--->" + dict.getDictCode());
        if (dict.getDictCode() > 1L) {
            return true;
        }
        return false;
    }

}

